package behavioral.command.base.cmds;

import behavioral.command.base.Command;
import behavioral.command.base.objs.Fan;

/**
 * 风扇命令
 */
public class FanHightCmd implements Command {
    private Fan fan;
    private int preSpeed; // 前一个风速,用于撤回

    public FanHightCmd(Fan fan) {
        this.fan = fan;
    }

    @Override
    public void execute() {
        fan.hight();
        preSpeed = fan.getSpeed();
    }

    @Override
    public void undo() {
        switch (preSpeed) {
            case Fan.HIGHT:
                fan.hight();
                break;
            case Fan.MEDIUM:
                fan.medium();
                break;
            case Fan.LOW:
                fan.low();
                break;
            case Fan.CLOSE:
                fan.off();
                break;
        }
    }
}
